package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.domain.Setmeal;
import com.itheima.entity.Result;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @PackageName: com.itheima.controller
 * @ClassName: SetmealController
 * @Author: Solomon
 * @Date: 2020/7/8 19:11
 * @Description:
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Reference
    private SetmealService setmealService;

    //查询所有套餐信息，用于套餐列表的展示
    @RequestMapping("/queryAllSetmeal")
    public Result queryAllSetmeal(){
        try {
            List<Setmeal> setmealList = setmealService.queryAllSetmeal();
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmealList);
        } catch (Exception e) {
            return new Result(false,MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    //根据id查询套餐的详细信息，用于展示套餐的详细信息
    @RequestMapping("/querySetmealById")
    public Result querySetmealById(Integer setmealId){
        try {
            Setmeal Setmeal = setmealService.querySetmealById(setmealId);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,Setmeal);
        } catch (Exception e) {
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    //移动端进行套餐预约时根据id查询套餐基本信息回显
    @RequestMapping("/findSetmealById")
    public Result findSetmealById(Integer setmealId){
        try {
            Setmeal setmeal = setmealService.findSetmealById(setmealId);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
